/**
 * 
 */
package com.study.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * @author Administrator
 * @date 2019年6月16日
 */
public class FutureTaskThreadDemo {

	public static void main(String[] args) {
		ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();
		FutureTask<Integer> future = (FutureTask<Integer>) newCachedThreadPool.submit(new Runnable(){
			@Override
		    public void run() {
		        for (int i=0; i < 5; i++) {
		            System.out.println(Thread.currentThread().getName() + " " + i);
		        }
		    }
		}, 100);  //100为自定义的线程指定返回结果

		System.out.println("主线程for循环执行完毕..");
        
        try {
            System.out.println("future.get() = " + future.get()); //100
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        
        newCachedThreadPool.shutdown();
    }
}
